package com.rxm.ys;

import com.rxm.ys.constant.HttpCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
 * @Description
 * @Author FengYi
 * @Date 2020-05-27 13:55
 */
@Data
@AllArgsConstructor
@Builder
public class Rs<T> {

    private int code;
    private String message;
    private T data;

    public static <T> Rs success(){
        return new Rs(HttpCodeEnum.SUCCESS.getCode(), HttpCodeEnum.SUCCESS.getDesc(), null);
    }

    public static <T> Rs success(String message){
        return new Rs(HttpCodeEnum.SUCCESS.getCode(), message, null);
    }

    public static <T> Rs success(String message, T data){
        return new Rs(HttpCodeEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> Rs data(T data){
        return new Rs(HttpCodeEnum.SUCCESS.getCode(), HttpCodeEnum.SUCCESS.getDesc(), data);
    }

    public static <T> Rs data(String message, T data){
        return new Rs(HttpCodeEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> Rs fail(){
        return new Rs(HttpCodeEnum.ERROR.getCode(), HttpCodeEnum.ERROR.getDesc(), null);
    }

    public static <T> Rs fail(String message){
        return new Rs(HttpCodeEnum.ERROR.getCode(), message, null);
    }
    public static <T> Rs fail(String message, T data){
        return new Rs(HttpCodeEnum.ERROR.getCode(), message, data);
    }
}
